package com.bjxst;

import java.io.FileInputStream;
import java.io.FileOutputStream;

/**通过缓冲区提高读写效率 方式一（常用）（效率比方式二慢点，但节省空间）*/
public class FileStream02 {
    public static void main(String[] args) {
        //定义字节流
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try{
            //创建字节流对象
            fis = new FileInputStream("e:/picture/1002.jpg");
            fos = new FileOutputStream("e:/aa.jpg");
            //创建数组，提高效率
            byte[] buff = new byte[1024];
            int temp = 0;
            while ((temp = fis.read(buff)) != -1){
                fos.write(buff,0,temp);
            }
            //保存在磁盘
            fos.flush();
        }catch (Exception e){

            e.printStackTrace();
        }finally {
            try {
                if (fis != null) {
                    fis.close();
                }
                if (fos != null){
                    fos.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }

    }
}
